473,480 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Menu help using JSwing

nomad
664 Recognized Expert Contributor
Hello everyone.
I have being trying to under stand a simple menu, and I have read alot of text on this, but I'm still confused.
I have found and re worked a simple menu and I need to find out how to make it work.
When you click on New how does it know where to go.
I'm working a project when a client click on "New" they will be prompt to enter a persons ID number, thou a Scanner. The scanner will check to see if the id number is listed or not. Info or data is stored in Arraylist.
Any advice or direction on how to do this would be great.

thanks
nomad


Expand|Select|Wrap|Line Numbers
  1. package company;
  2.  
  3.  
  4. import java.awt.*;
  5. import javax.swing.*;
  6. import java.awt.event.*;
  7.  
  8.  
  9.  
  10. /**
  11. * @param args
  12. */
  13.  
  14.     // TODO Auto-generated method stub
  15.     /*
  16.     <APPLET
  17.      CODE = menu.class
  18.          WIDTH = 350
  19.          HEIGHT = 280 >
  20.     </APPLET>
  21.     */
  22.  
  23. public class Sample_menu extends JApplet implements ActionListener
  24.         {
  25.             public void init()
  26.             {
  27.     JMenuBar jmenubar = new JMenuBar();
  28.  
  29.     JMenu jmenu1 = new JMenu("File");
  30.     JMenuItem jmenuitem1 = new JMenuItem("New..."),
  31.             jmenuitem2 = new JMenuItem("Find.."),
  32.             jmenuitem3 = new JMenuItem("Exit");
  33.  
  34.     jmenu1.add(jmenuitem1);
  35.     jmenu1.add(jmenuitem2);
  36.     jmenu1.addSeparator();
  37.     jmenu1.add(jmenuitem3);
  38.  
  39.     jmenuitem1.setActionCommand("You selected New");
  40.     jmenuitem2.setActionCommand("You selected Find");
  41.  
  42.     jmenuitem1.addActionListener(this);  //
  43.     jmenuitem2.addActionListener(this);
  44.  
  45.  
  46.         jmenubar.add(jmenu1);
  47.         setJMenuBar(jmenubar);
  48.             }
  49.  
  50.  public void actionPerformed(ActionEvent e)
  51.         {
  52.              JMenuItem jmenuitem = (JMenuItem)e.getSource();
  53.  
  54.              showStatus(jmenuitem.getActionCommand());
  55.          }
  56.  
  57. }
  58.  
  59. kbd = new Scanner(System.in);
  60.         System.out.print("\nPlease press Enter afer each response");
  61.         System.out.print("Enter ther Employee ID Number");
  62.        abc_flag  = kbd.nextInt();
  63.  
  64.  
Mar 22 '07 #1
1 1810
r035198x
13,262 MVP
Hello everyone.
I have being trying to under stand a simple menu, and I have read alot of text on this, but I'm still confused.
I have found and re worked a simple menu and I need to find out how to make it work.
When you click on New how does it know where to go.
I'm working a project when a client click on "New" they will be prompt to enter a persons ID number, thou a Scanner. The scanner will check to see if the id number is listed or not. Info or data is stored in Arraylist.
Any advice or direction on how to do this would be great.

thanks
nomad


Expand|Select|Wrap|Line Numbers
  1. package company;
  2.  
  3.  
  4. import java.awt.*;
  5. import javax.swing.*;
  6. import java.awt.event.*;
  7.  
  8.  
  9.  
  10. /**
  11. * @param args
  12. */
  13.  
  14.     // TODO Auto-generated method stub
  15.     /*
  16.     <APPLET
  17.     CODE = menu.class
  18.          WIDTH = 350
  19.          HEIGHT = 280 >
  20.     </APPLET>
  21.     */
  22.  
  23. public class Sample_menu extends JApplet implements ActionListener
  24.         {
  25.          public void init()
  26.          {
  27.     JMenuBar jmenubar = new JMenuBar();
  28.  
  29.     JMenu jmenu1 = new JMenu("File");
  30.     JMenuItem jmenuitem1 = new JMenuItem("New..."),
  31.          jmenuitem2 = new JMenuItem("Find.."),
  32.          jmenuitem3 = new JMenuItem("Exit");
  33.  
  34.     jmenu1.add(jmenuitem1);
  35.     jmenu1.add(jmenuitem2);
  36.     jmenu1.addSeparator();
  37.     jmenu1.add(jmenuitem3);
  38.  
  39.     jmenuitem1.setActionCommand("You selected New");
  40.     jmenuitem2.setActionCommand("You selected Find");
  41.  
  42.     jmenuitem1.addActionListener(this); //
  43.     jmenuitem2.addActionListener(this);
  44.  
  45.  
  46.         jmenubar.add(jmenu1);
  47.         setJMenuBar(jmenubar);
  48.          }
  49.  
  50. public void actionPerformed(ActionEvent e)
  51.         {
  52.          JMenuItem jmenuitem = (JMenuItem)e.getSource();
  53.  
  54.          showStatus(jmenuitem.getActionCommand());
  55.          }
  56.  
  57. }
  58.  
  59. kbd = new Scanner(System.in);
  60. System.out.print("\nPlease press Enter afer each response");
  61. System.out.print("Enter ther Employee ID Number");
  62. abc_flag = kbd.nextInt();
  63.  
  64.  
You are using swing and yet you are trying to get input using the console.
Use swing to get the input as well. You put the code for taking the input inside the appropriate action handling method.
Mar 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2615
by: Rick | last post by:
Hi, I'm having problems with Java applets. I just generated a JApplet (also tried normal Applet) in Netbeans which is delivered with the newest JDK. When I compile it in Netbeans it seems to...
2
3846
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
8
10063
by: Dennis C. Drumm | last post by:
Is there a way to modify the standard context menu shown when someone right clicks in a windows text box and that would work for all open windows applications? The standard context menu for...
7
2656
by: Chuck Hartman | last post by:
I have a Windows service that requests web pages from a site using an HttpWebRequest object. When I try to request a page from an ASP.NET 2 site, I get a WebException with message "The remote...
1
6318
by: goRide | last post by:
Hi, I'm looking of a way (preferred - a ready class or dll) to customize the context menu. many application has more controls inside the context menu (like textbox, sliders, checkbox, panel...
4
4122
by: Bob Homes | last post by:
In VB6, I used a system, which I loved, whereby I assigned a "helpId" to each menu item; that way, you could rest the cursor on the item (without actually running it) and then press F1 to get...
6
1863
by: Ben Fidge | last post by:
Hi I've just created a new Master Page for my site and it uses the native Menu control. Strange behaviour is happening on page that use the master page. For some reason, the menu controls...
2
3038
by: Gary Wessle | last post by:
Hi I need help organizing this program in the right way. I included the code below which compiles and runs and gives the desired effect to a certain point, but I don't know what the next step...
1
2144
by: Anthony | last post by:
Below is a script I found at http://javascript.internet.com/ for a cascading menu. The script works great but there is one thing that I would like modified. BecauseI am just learning javascript,...
0
6908
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7048
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5342
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4783
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
2997
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2986
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
563
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
183
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.